package edu.siu.math.egut.functions;

import edu.siu.math.egut.egut.Algorithms;
import edu.siu.math.egut.lie.AbstractEgutFunction;
import edu.siu.math.egut.lie.LiEGroup;
import edu.siu.math.egut.lie.LiEType;
import edu.siu.math.egut.lie.LiEVector;
import edu.siu.math.egut.util.ExceptionalGroup;



/**
 * Example egut function that can be run from the egut interpreter with the
 * syntax: egutIsRoot(vec root, grp group).
 * 
 * @author Joe Pleso
 *
 */
public class IsRoot extends AbstractEgutFunction {

		
	
	

	
	public LiEType[] argList() {
	    LiEType[] result = new LiEType[2];
	    result[0]=LiEType.VEC;
	    result[1]=LiEType.GRP;
	    return result;
	    //Define the arguments this function takes
	}

	
	public void run() {
	    String [] args = this.getRawData();
	    //Get the arguments from the interpreter
	    
	    LiEVector lieV = new LiEVector(args[0]);
	    int[] root = (int[]) lieV.getJavaObject();
	    //Get the root to check
	    
	    LiEGroup lieG = new LiEGroup(args[1]);
	    ExceptionalGroup rs = (ExceptionalGroup)lieG.getJavaObject();
	    //Get the group
	    
	    
	    if (rs == null){//Make sure that we really have a group
		args[0] = Algorithms.LIE_QUOTE
		+ " is not an exceptional group." +
		Algorithms.LIE_QUOTE;
		this.setData(args);
		return;
	    }
	   
	    if (rs.isRoot(root)){//Check if its a root...
		args[0] = Algorithms.LIE_QUOTE 
		+ lieV.toString() 
		+ " is a root in " 
		+ lieG.toString() + "." + Algorithms.LIE_QUOTE;
		this.setData(args);
		return;
	    }else//or not
	    {
		args[0] = Algorithms.LIE_QUOTE
		+ lieV.toString()
		+ " is not a root in " 
		+ lieG.toString() + "." + Algorithms.LIE_QUOTE;
		//and prepare the LiE text to display
		this.setData(args);//send it back to the interpreter
		return;//done
	    }
	    
	}

}
